#pragma once
#pragma warning(disable:4996)       // disable checked iterator errors http://msdn.microsoft.com/en-us/library/aa985965(VS.80).aspx 

//
// Copyright (C) 2011 Steve Channell steve.channell@cepheis.com
//
// This file is part of Cephei.QL, an open-source library wrapper 
// arround QuantLib http://quantlib.org/
//
// Cephei.QL is open source software: you can redistribute it and/or modify it
// under the terms of the license.  You should have received a
// copy of the license along with this program; if not, please email
// <support@cepheis.com>. The license is also available online at
// <http://cepheis.com/license.htm>.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE.  See the license for more details.
//
// Version 2.101

#include <Macros.h>
#include <CoVector.h>
#include <CoMatrix.h>
#include <CoCube.h>
#include <ValueHelpers.h>
#include <Settings.h>

#include <gen/QL/TermStructure.h>
#pragma unmanaged 
#include <ql\termstructures\defaulttermstructure.hpp>
#include <boost/smart_ptr/detail/spinlock.hpp>
#pragma managed 

using namespace System;
using namespace QuantLib;
using namespace Cephei;

using namespace Cephei::QL::Times;
using namespace Cephei::QL;
#define HANDLE
#define ABSTRACT
#undef STRUCT
namespace Cephei { namespace QL { namespace Termstructures {
	//////////////////////////////////////////////////////////////////////////////////////////////
	// implementation of IDefaultProbabilityTermStructure
	public ref class CDefaultProbabilityTermStructure : 
            public CTermStructure,
            public Cephei::QL::Termstructures::IDefaultProbabilityTermStructure
	{
	protected: 
		boost::shared_ptr<QuantLib::DefaultProbabilityTermStructure>* _ppDefaultProbabilityTermStructure;
#ifdef HANDLE
		QuantLib::Handle<QuantLib::DefaultProbabilityTermStructure>* _phDefaultProbabilityTermStructure;
#endif
		Object^ _DefaultProbabilityTermStructureOwner;     // reference to object that manages the storage for this object
	internal:
        CDefaultProbabilityTermStructure (boost::shared_ptr<QuantLib::DefaultProbabilityTermStructure>& childNative, Object^ owner);
        CDefaultProbabilityTermStructure (QuantLib::DefaultProbabilityTermStructure& childNative, Object^ owner);
        CDefaultProbabilityTermStructure (CDefaultProbabilityTermStructure^ copy);
        CDefaultProbabilityTermStructure (System::Type^ t);
#ifdef STRUCT
        CDefaultProbabilityTermStructure (QuantLib::DefaultProbabilityTermStructure childNative);
#endif       
#ifdef HANDLE
		CDefaultProbabilityTermStructure (QuantLib::Handle<QuantLib::DefaultProbabilityTermStructure>& childNative, Object^ owner);
		CDefaultProbabilityTermStructure (QuantLib::Handle<QuantLib::DefaultProbabilityTermStructure> childNative);
#endif
		virtual ~CDefaultProbabilityTermStructure ();
		!CDefaultProbabilityTermStructure ();

	internal:
		QuantLib::DefaultProbabilityTermStructure& GetReference ();
		boost::shared_ptr<QuantLib::DefaultProbabilityTermStructure>& GetShared ();
		QuantLib::DefaultProbabilityTermStructure* GetPointer ();
        void SetDefaultProbabilityTermStructure (boost::shared_ptr<QuantLib::DefaultProbabilityTermStructure> native)
        {
            if (_ppDefaultProbabilityTermStructure != NULL)
                delete _ppDefaultProbabilityTermStructure;
            _ppDefaultProbabilityTermStructure = new boost::shared_ptr<QuantLib::DefaultProbabilityTermStructure> (native);
            SetTermStructure (boost::dynamic_pointer_cast<QuantLib::TermStructure> (*_ppDefaultProbabilityTermStructure));
        }
#ifdef HANDLE
		QuantLib::Handle<QuantLib::DefaultProbabilityTermStructure>& GetHandle ();
#endif
		virtual bool HasNative () override;
    public:
		virtual Double DefaultDensity (Double t, Microsoft::FSharp::Core::FSharpOption<Boolean>^ extrapolate) ;
		virtual Double DefaultProbability (Double t1, Double t2, Microsoft::FSharp::Core::FSharpOption<Boolean>^ extrapo) ;
		virtual Double DefaultProbability (DateTime d1, DateTime d2, Microsoft::FSharp::Core::FSharpOption<Boolean>^ extrapolate) ;
		virtual Double DefaultProbability (Double t, Microsoft::FSharp::Core::FSharpOption<Boolean>^ extrapolate) ;
		virtual Double DefaultProbability (DateTime d, Microsoft::FSharp::Core::FSharpOption<Boolean>^ extrapolate) ;
        property Cephei::IVector<DateTime>^ JumpDates 
        {
		    virtual Cephei::IVector<DateTime>^ get () ;
        }
		virtual Double SurvivalProbability (Double t, Microsoft::FSharp::Core::FSharpOption<Boolean>^ extrapolate) ;
		virtual Double SurvivalProbability (DateTime d, Microsoft::FSharp::Core::FSharpOption<Boolean>^ extrapolate) ;
        property Cephei::IVector<Double>^ JumpTimes 
        {
		    virtual Cephei::IVector<Double>^ get () ;
        }
        property Cephei::QL::Termstructures::IDefaultProbabilityTermStructure^ Update 
        {
		    virtual Cephei::QL::Termstructures::IDefaultProbabilityTermStructure^ get () ;
        }
		virtual Double DefaultDensity (DateTime d, Microsoft::FSharp::Core::FSharpOption<Boolean>^ extrapolate) ;
		virtual Double HazardRate (Double t, Microsoft::FSharp::Core::FSharpOption<Boolean>^ extrapolate) ;
		virtual Double HazardRate (DateTime d, Microsoft::FSharp::Core::FSharpOption<Boolean>^ extrapolate) ;
    };
	//////////////////////////////////////////////////////////////////////////////////////////////
	// implementation of IDefaultProbabilityTermStructure Vector interface
	ref class CDefaultProbabilityTermStructureVector : public System::MarshalByRefObject,  
							    public INativeVector<IDefaultProbabilityTermStructure^>,
							    public INativeVector<Generic::ICell<IDefaultProbabilityTermStructure^>^>
	{
	private:
#ifdef STRUCT
		std::vector<QuantLib::DefaultProbabilityTermStructure>* _pVValue;
#endif        
		std::vector<boost::shared_ptr<QuantLib::DefaultProbabilityTermStructure>>* _pVBoost;
#ifdef HANDLE
		std::vector<QuantLib::Handle<QuantLib::DefaultProbabilityTermStructure>>* _pVHand;
#endif
		Object^ _owner;		// object reference to prevent GC of vector owner

	internal:
		CDefaultProbabilityTermStructureVector ();
#ifdef STRUCT
		CDefaultProbabilityTermStructureVector (std::vector<QuantLib::DefaultProbabilityTermStructure>& vec, Object^ owner);
		CDefaultProbabilityTermStructureVector (std::vector<QuantLib::DefaultProbabilityTermStructure> vec);
#endif       
		CDefaultProbabilityTermStructureVector (std::vector<boost::shared_ptr<QuantLib::DefaultProbabilityTermStructure>>& vec, Object^ owner);
#ifdef HANDLE
		CDefaultProbabilityTermStructureVector (std::vector<QuantLib::Handle<QuantLib::DefaultProbabilityTermStructure>>& vec, Object^ owner);
#endif
		virtual ~CDefaultProbabilityTermStructureVector ();
		!CDefaultProbabilityTermStructureVector ();

    public:
		property int Count 
		{
			virtual int get ();
		}

		property IDefaultProbabilityTermStructure^ default[int] 
		{
			virtual IDefaultProbabilityTermStructure^ get (int index) = INativeVector<IDefaultProbabilityTermStructure^>::default::get;
			virtual void set (int index, IDefaultProbabilityTermStructure^ value) = INativeVector<IDefaultProbabilityTermStructure^>::default::set;
		}

		//////////////////////////////////////////////////////////////////////////////////////////
		// Interface functions for cell vectors 
	public:
		property Generic::ICell<Cephei::QL::Termstructures::IDefaultProbabilityTermStructure^>^ CItem[int] 
		{
			virtual Generic::ICell<IDefaultProbabilityTermStructure^>^ get (int index) = INativeVector<Generic::ICell<IDefaultProbabilityTermStructure^>^>::default::get;
			virtual void set (int index, Generic::ICell<IDefaultProbabilityTermStructure^>^ value) = INativeVector<Generic::ICell<IDefaultProbabilityTermStructure^>^>::default::set;
		}
	internal:
#ifdef STRUCT    
		std::vector<QuantLib::DefaultProbabilityTermStructure>& GetReference ();
#endif     
		std::vector<boost::shared_ptr<QuantLib::DefaultProbabilityTermStructure>>& GetShared ();

#ifdef HANDLE
		std::vector<QuantLib::Handle<QuantLib::DefaultProbabilityTermStructure>>& GetHandle ();
#endif
	public:
		virtual bool PrepareFeature (NativeFeature feature);
	};
    
	//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	// Factory class
	public ref class CDefaultProbabilityTermStructure_Factory : public System::MarshalByRefObject,  public IDefaultProbabilityTermStructure_Factory
	{
	public:
        /* <summary> Create a hybrid Vector of IDefaultProbabilityTermStructure, with event notification of changes </summary> */
        virtual Cephei::IVector<IDefaultProbabilityTermStructure^>^ CreateVector();
        /* <summary> Create a hybrid Vector of ICell of IDefaultProbabilityTermStructure, with event notification of changes </summary> */
        virtual Generic::ICell<Cephei::IVector<Generic::ICell<IDefaultProbabilityTermStructure^>^>^>^ CreateCellVector();
        virtual Cephei::IVector<IDefaultProbabilityTermStructure^>^ CreateVector(System::Collections::Generic::IEnumerable<IDefaultProbabilityTermStructure^>^ source);
        virtual Generic::ICell<Cephei::IVector<Generic::ICell<IDefaultProbabilityTermStructure^>^>^>^ CreateCellVector(System::Collections::Generic::IEnumerable<Generic::ICell<IDefaultProbabilityTermStructure^>^>^ source);
    };
   
/*Cephei*/ } /*QL*/ } /*Termstructures */}
